<?php

namespace App\Repositories;

use App\Models\ChannelVisitDay;
use InfyOm\Generator\Common\BaseRepository as iBaseRepository;

class ChannelVisitDayRepository extends iBaseRepository
{
    /**
     * @var array
     */
    protected $fieldSearchable = [
        'channel_id',
        'visit_date',
        'visit_num',
        'status'
    ];

    /**
     * Configure the Model
     **/
    public function model()
    {
        return ChannelVisitDay::class;
    }

    /**
     * 保存渠道访问
     */
    public function saveChannelDayVisit($channelId)
    {
        $attributes = [
            'channel_id' => $channelId,
            'visit_date' => now()->toDateString()
        ];
        $visit = parent::firstOrCreate($attributes);
        $visit->increment('visit_num');

        return $visit;
    }
}
